<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>HR公司信息</title>  
</head>
<body>
<div class="ui segment" id="n-page">
        <div class="ui segment" id="n-content">
            <form class="ui form">
                    
                <div class="field">
                    <label><span style="color: red">*</span>公司名称</label>
                    <div class="ui search" id="companyname" name="companyname">
                        <div class="ui input">
                            <input class="prompt" type="text" placeholder="请输入公司名称" value="${hunter.companyName}">
                        </div>
                        <div class="results"></div>
                    </div>
                </div>
                <!--
                <div class="field">
                    <label>组织机构代码</label>
                    <div class="ui input">
                        <input type="text" name="orgcode" id="orgcode" value="${tempcompany.orgnizationCode}" placeholder="请输入组织机构代码">
                    </div>
                </div>
                -->
                <div class="field">
                    <label><span style="color: red">*</span>Company Name</label>
                    <div class="ui input">
                        <input type="text" name="englishname" id="englishname" value="${tempcompany.englishname}" placeholder="请输入公司英文名称">
                    </div>
                </div> 
                <div class="field">
                    <label><span style="color: red">*</span>地址</label>
                    <div class="ui input">
                        <input type="text" name="companyaddress" id="companyaddress" value="${tempcompany.address}" placeholder="请输入公司地址">
                    </div>
                </div>                   
                <input type="hidden" name="employerId" id="employerId" value="${employer.id}"/>
                <!--
                <input type="hidden" name="compId" id="compId" value="${employer.companyId}"/>
                -->
            </form>        
        </div>
      
        <div class="ui segment" id="btn-next2">
            <div class="fluid ui button" id="next">保存</div>
        </div>
        
       <!--  <div class="ui center aligned segment" id="choice-buttons"> 
            <div class="two ui buttons"> 
                <div class="ui button active dog" id="next">下一步</div> 
                <div class="ui button active dog" id="closeit">回首页</div> 
            </div>
        </div> -->
</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu',
        'closeWindow']  
});
    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }

            if($(this).attr('id') == 'next') {

                var companyid = $("#companyid").val();
                var hrid = $("#employerId").val();
                var bindedCompanyId = $("#compId").val();
                //var orgcode  = $("#orgcode").val();
                //var bizcode  = $("#bizcode").val();
                //if(!bizcode || bizcode=="") {
                  //  alert("您必须输入营业执照编码");
                    //return false;
                //}
                 var companyaddress = $("#companyaddress").val();
                 if(!companyaddress || companyaddress=="" || companyaddress.length > 50) {
                   alert("您必须输入公司地址");
                   return false;
               }
                var companyname = $('#companyname').search('get value');
                if(!companyname || companyname=="") {
                    alert("您必须输入公司名称");
                    return false;
                }
                if(companyname.length > 40) {
                    alert("公司名字太长");
                    return false;
                }
                
                
                $(this).addClass('disabled');
                var that = this;
                //var postUrl = '${ctx}/wechat/company/create.do';
                var postUrl = '${ctx}/wechat/company/create2_2.do';
               
                var param = {};
                 
              
                param['hrid']    = hrid;
                //param['orgcode'] = orgcode;
                //param['bizcode'] = bizcode;
                param['companyaddress']=companyaddress;
                param['englishname']= $("#englishname").val();
                param['companyname'] = companyname;
                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(response) { 
                        if(response.errorcode=="0") {
                            alert(response.msg);
                            //forwardUrl = "${ctx}/wechat/employer/main.page";//to upload img
                           <%--forwardUrl = "${ctx}/wechat/hr/toUploadFile.page";//to upload img--%>
                           <%--  --%>
                           <%-- location.href = forwardUrl;--%>
                            alert("更新成功")
                            wx.closeWindow();
                            return;
                        } 
                        /**else if(response.errorcode == "1") {
                            //alert(response.msg);
                            var forwardUrl = "${ctx}/wechat/company/toCreate2_2.page";
                            location.href = forwardUrl;
                            return;
                        }*/ 
                        else if(response.errorcode == "3") {
                            alert(response.msg);
                            $(that).removeClass('disabled');
                            return;
                        } else {
                            alert(response.msg);
                            var forwardUrl = "${ctx}/wechat/headhunter/errorpage";
                            location.href = forwardUrl;
                            return;
                        }
                    },
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                        $(that).removeClass('disabled');
                    } 
                });

            }
        } 
    };

    var companydata = [];
    
    <c:forEach items="${companies}" var="company">
        var tmp${company.id} = {};
        tmp${company.id}.title = "${company.name}";
        companydata.push(tmp${company.id});
    </c:forEach>

    $(document).ready(function() { 
       
            $('.button').on('click', handler.activate);
            $('.ui.search').search({
                source: companydata,
                searchFullText: true
            });
            wx.ready(function() { 
            wx.hideOptionMenu();

        });
    });

</script>
</body>
</html>